﻿using Microsoft.AspNetCore.Http;
using SBlogCore.Entitys.SystemManager;
using SBlogCore.WebAdminApplication.SysManager.Dto;
using SBlogCore.WebAdminApplication.SysManager.IServices;

namespace SBlogCore.WebAdminApplication.SysManager.Controller
{
    public class SysFileInfoController : AuthorizeBaseController
    {
        private readonly ISysFileInfoService _sysFileInfoService;

        public SysFileInfoController(ISysFileInfoService sysFileInfoService)
        {
            this._sysFileInfoService = sysFileInfoService;
        }
        /// <summary>
        /// 文件上传
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<List<SysFileInfoOutPut>> SaveImageFile(IFormFileCollection files)
        {
            var fileList= files.ToList();
            return await _sysFileInfoService.SaveImageFile(fileList);
        }
        /// <summary>
        /// 加载列表
        /// </summary>
        /// <param name="inPut"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<PageList<SysFileInfoQueryOutPut>> GetList([FromQuery]SysFileInfoQueryInPut inPut)
        {
            PageList<SysFileInfo> res = await _sysFileInfoService.GetList(inPut);
            return res.Adapt<PageList<SysFileInfoQueryOutPut>>();
        }
        /// <summary>
        /// 删除文件
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task DeleteFile(long id)
        {
            await _sysFileInfoService.DeleteFile(id);
        }
    }
}
